#!/bin/bash

export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
export GOSUMDB=off
export CGO_ENABLED=0

OUTPUT_DIR="dist"
mkdir -p $OUTPUT_DIR

echo "开始交叉编译 ssh-tunnel..."

# 构建目标列表：os arch output_name
targets=(
  "windows amd64 $OUTPUT_DIR/ssh-tunnel_windows_amd64.exe"
  "windows 386 $OUTPUT_DIR/ssh-tunnel_windows_386.exe"    # 新增：Windows 32位
  "linux amd64 $OUTPUT_DIR/ssh-tunnel_linux_amd64"
  "linux arm64 $OUTPUT_DIR/ssh-tunnel_linux_arm64"
  "darwin amd64 $OUTPUT_DIR/ssh-tunnel_macos_amd64"
  "darwin arm64 $OUTPUT_DIR/ssh-tunnel_macos_arm64"
)

for target in "${targets[@]}"; do
  read -r GOOS GOARCH OUTPUT <<< "$target"
  echo "构建 $GOOS/$GOARCH ..."
  GOOS=$GOOS GOARCH=$GOARCH go build -o "$OUTPUT" || exit 1
done

echo "✅ 所有平台构建完成！输出目录: $OUTPUT_DIR"
ls -lh $OUTPUT_DIR